<?php 
class minify{
	/* gets the version tag of the minpack (either js or css) 
	 * to use for appending onto the filename so that the client 
	 * pulls a new minpack once it changed on the server. The
	 * tag itself is the timestamp of the file that has been
	 * last changed. The minpack variables holds the minpack
	 * from the config.php which has all filenames as a string
	 * separated by a semicolon (;) */
	public static function getMinpackTag($minpack){
		$result = 0;
		
		$fileList = explode(";",$minpack);
		for($f=0;$f<count($fileList);$f++){
			$mtime = filemtime(CONFIG_ROOTDIR.$fileList[$f]);
			if($mtime>$result){$result=$mtime;}
		}
		
		return $result;
	}
	
	/* minifies html code and its javascript stuff */
	public static function minifyHtml($html){
		$result = $html;
		
		// minify the html and its javascript
		$result = Minify_HTML::minify($result, 
			array("jsMinifier" => 'Minify_Javascript::minify'));
		
		return $result;
	}	
	
	/* minifies javascript code */
	public static function minifyJS($js){
		$result = $js;
		$result = Minify_Javascript::minify($result);
		return $result;
	}
	
	/* minifies css code */
	public static function minifyCSS($css){
		$minified = $css;
		
		// remove css comments from the data
		$minified = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $minified);
		
		// tabs are not required, just use spaces
		$minified = str_replace("\t","",$minified);
		$minified = str_replace("{ ","{",$minified);
		$minified = str_replace(" {","{",$minified);
		$minified = str_replace("; ",";",$minified);
		$minified = str_replace(": ",":",$minified);
		
		// in css we can remove all line breaks
		$minified = str_replace("\n","",$minified);
		
		return $minified;
	}
}
?>